package com.idol.logger.core.format

import com.idol.logger.core.format.iface.IStackTraceFormat

internal class IdolStackTraceFormat : IStackTraceFormat() {

    override fun formatter(data: Array<StackTraceElement>) = when (val size = data.size) {
        0 -> ""
        1 -> "\t-${data[0].toString()}"
        else -> {
            data.foldIndexed(StringBuilder(128)) { index, sb, element ->
                if (index == 0) sb.append("StackTrace: ").append("\n")
                if (index != size - 1)
                    sb.append("\t├").append(element.toString()).append("\n")
                else
                    sb.append("\t└").append(element.toString())
            }.toString()
        }
    }

}